What is While loop in C language

 While Loop in C language


The while loopIt is a often a case in programming that you want you do somethinga fixed number of times. Perhaps you want to calculate gross salaries of ten different persons, or you want to convert

temperatures from centigrade to fahrenheit for 15 different cities.


The while loop is ideally suited for such case 

simple example, Let us look at a hich uses a while loop. The flowchart shown below would help you to understand the operation of the while loop.

While Loop



/* Calculation of simple interest for 3 sets of p, n and r */ 

main( ) 

int p, n, count ; 

float r, si ;

count=1;

while ( count <= 3 ) 

 { 

 printf ( "\nEnter values of p, n and r " ) ;

scanf(" %d%d%d,&p,&n,&r);

si =p*n*r;

printf ( "Simple interest = Rs. %f", si ) ;

count=count+1;

}

}

The operation of the while loop is illustrated in the following figure.


Note:- above information taken from "Let's C" book.




Post a Comment (0)
Previous Post Next Post